package cn.zhpdmmz.hotel.controller;

import cn.zhpdmmz.entity.CheckInformationDetails;
import cn.zhpdmmz.service.ICheckInformationDetailsService;
import cn.zhpdmmz.vo.CheckInVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import java.util.Map;

/**
 * (CheckInformationDetails)表控制层
 *
 * @author CJW
 * @since 2022-03-26 17:22:34
 */
@RestController
@RequestMapping("checkInformationDetails")
public class CheckInformationDetailsController {
    /**
     * 服务对象
     */
    @Autowired
    private ICheckInformationDetailsService checkInformationDetailsService;

    /**
     * 分页查询
     *
     * @param checkInformationDetails 筛选条件
     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<CheckInformationDetails>> queryAll(CheckInformationDetails checkInformationDetails) {
        return ResponseEntity.ok(this.checkInformationDetailsService.queryAll(checkInformationDetails));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<CheckInformationDetails> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.checkInformationDetailsService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param checkInformationDetails 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<CheckInformationDetails> add(@RequestBody CheckInformationDetails checkInformationDetails) {
        return ResponseEntity.ok(this.checkInformationDetailsService.insert(checkInformationDetails));
    }

    /**
     * 编辑数据
     *
     * @param checkInformationDetails 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<CheckInformationDetails> edit(@RequestBody CheckInformationDetails checkInformationDetails) {
        return ResponseEntity.ok(this.checkInformationDetailsService.update(checkInformationDetails));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Integer id) {
        return ResponseEntity.ok(this.checkInformationDetailsService.deleteById(id));
    }

    @GetMapping("/page")
    public PageInfo page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, CheckInformationDetails checkInformationDetails) {
        PageHelper.startPage(pageNum,pageSize);
        List<CheckInformationDetails> list = this.checkInformationDetailsService.queryAll(checkInformationDetails);
        PageInfo<List> pageInfo = new PageInfo(list);
        return pageInfo;
    }
    /**
     * 添加客户
     * 步骤1
     * @return 新增结果
     */
    @GetMapping("/addCustomer")
    public ResponseEntity<Map<String, Object>> addCustomer(CheckInVo checkInVo) {
        return ResponseEntity.ok(this.checkInformationDetailsService.addCustomer(checkInVo));
    }
    /**
     * 取消添加客户
     * 步骤1—1
     * @return 新增结果
     */
    @PostMapping("/cancelAddCustomer")
    public ResponseEntity <Boolean> cancelAddCustomer() {
        return ResponseEntity.ok(this.checkInformationDetailsService.cancelAddCustomer());
    }
    /**
     * 办理入住
     * 步骤2
     * @return 新增结果
     */
    @GetMapping("/checkIn")
    public ResponseEntity <Boolean> checkIn(CheckInVo checkInVo) {
        return ResponseEntity.ok(this.checkInformationDetailsService.checkIn(checkInVo));
    }
}
